package lu.med.praxiswahl.wahlumed.client.zytologie;

import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

/**
 * 
 * @author Lars Holger Roth
 */
public class ZytologieTableSelectionListener implements ListSelectionListener {

	private ZytologieTableModel tableModel;

	public ZytologieTableSelectionListener(ZytologieTableModel tableModel) {
		this.tableModel = tableModel;
	}

	public void valueChanged(ListSelectionEvent e) {
		if (e.getValueIsAdjusting()) {
			return;
		}
		ListSelectionModel lsm = (ListSelectionModel) e.getSource();
		if (lsm.isSelectionEmpty()) {
			tableModel.setSelected(-1);
		} else {
			int selectedRow = lsm.getMinSelectionIndex();
			tableModel.setSelected(selectedRow);
		}
	}

}
